package com.vm.log4j;

import java.io.FileNotFoundException;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.vm.common.Var;
import com.vm.common.WebRootPath;


/**
 * 得到自定义的log4j 的logger 重新设定logger的存放路径
 * 
 * @author lh 2011-04-18
 * 
 */
public class CustomizeLog4j {

	// public static void main(String[] arg) {
	// String a = null;
	// try {
	// boolean b = a.equals("1");
	// } catch (java.lang.NullPointerException e) {
	// Logger _log = FCLogger.getLogger(FCLogger.class);
	// _log.error(e);
	// }
	// }

	@SuppressWarnings("unchecked")
	public static Logger getLogger(Class classzz) {
		return Logger.getLogger(classzz);
	}

	static {
		initLogger();
	}

	private static void initLogger() {

		InputStream inputStream = null;
		try {// 先装载默认配置
			inputStream = CustomizeLog4j.class.getResourceAsStream("/log4j.properties");

			Properties pro = new Properties();
			pro.load(inputStream);

			StringBuffer filebf = new StringBuffer();
			filebf.append(WebRootPath.getRootPath());
			filebf.append(Var.LOG4J_FILE_SAVE_PATH);

			pro.setProperty("log4j.appender.R.File", filebf.toString());

			PropertyConfigurator.configure(pro);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (inputStream != null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

}
